***********************************************************
*	 	
*	The Long-Term Impact of High School Financial Education: Evidence from Brazil
*	Miriam Bruhn, Gabriel Garber, Sergio Koyama, and Bilal Zia
*
*	Stata Replication code
*
*	
**************************************************************************************************************************************************************


clear
macro drop _all
capture log close
macro def dta "dta path" //replace with folder where dta files and income.xlsx are saved
macro def results "results path"	//replace with folder where results must be saved
macro def logs "logs path"	//replace with folder where logs must be saved
	mata mata mlib index
	set more off
	capture adopath - OLDPLACE
	capture adopath - PERSONAL

sysdir set PLUS "stata added packages path" //replace with folder where Stata added packages are or will be installed

*Obs: uncomment ssc commands if packages not yet installed: 
* ssc install reghdfe
* ssc install unique
* ssc install outreg2
* ssc install ftools
* ssc install estout
* scc install winsor2	

	
log using "$logs\LTimpactFE.log", replace


*import PNAD wages and other variables


import excel  "$dta\income.xlsx", sheet("Sheet1") firstrow


gen cd_uf=.

	replace cd_uf=17 if State=="TO"
	replace cd_uf=23 if State=="CE"
	replace cd_uf=31 if State=="MG"
	replace cd_uf=33 if State=="RJ"
	replace cd_uf=35 if State=="SP"
	replace cd_uf=53 if State=="DF"
	

gen female=0
replace female=1 if Gender=="F"


replace occupation="informal proxy" if occupation=="informal"


	
 save "$dta\PNAD_wages_draft.dta", replace
*/
cd "$results"
***************************************************
***												***
*** Dataset for tables 1 and A1 through A4  	***
***												***
***************************************************

			
			
*Table 1 - Baseline Summary Statistics for Long-Term IE Sample


		use "$dta\intervention_data.dta", clear	
		keep if  sample==1
		keep if round==1
			
	


		* Outcomes
		global test female dumm_rp_08_bl dumm_rp_09_bl dumm_rp_24_bl dumm_rp_14_bl dumm_rp_23_bl dumm_rp_50_bl ///
		 dumm_rp_49_bl vl_proficiencia_bl   dumm_rp_65A_bl poupar_final2_bl dumm_rp_64A_bl dumm_negotiates_bl autonomia_final2_bl 
		global school matriculas docentes abandonona1sriemdio aprovaona1sriemdio 
		global xvars  $school $test

		* Matrix for output
		global z: word count $xvars 


		*baseline balance checks within samples

			
		egen tag_school = tag(cd_escola) //gen 1 for the first time cd_escola shows up
		egen tag_school_test = tag(cd_escola) if bl_test == 1 // students took the fin lit test at baseline
		egen tag_school_aluno = tag(cd_escola) if bl_aluno == 1 // students answered baseline questionaire
				
		matrix T = J($z, 7, . ) 
		matrix rownames T = $xvars
		matrix colnames T = ns n Control sdC Treatment sdT pv 

		* Estimation

		foreach var in $school { 
			global `var'label: var label `var' 

			reg `var' treatment if tag_school == 1, clu(cd_escola)
				g sample_`var' = (e(sample)==1) 
				local pr = 2*ttail(e(df_r),abs(_b[treatment]/_se[treatment])) 
				mat T[rownumb(T, "`var'"), colnumb(T,"pv")] = `pr' 
			
			sum `var' if tag_school == 1 & sample_`var' == 1, d
			mat T[rownumb(T, "`var'"), colnumb(T,"ns")] = `r(N)' 
			
			sum `var' if tag_school == 1 & sample_`var' == 1 & treatment == 1 
				mat T[rownumb(T, "`var'"), colnumb(T,"sdT")] = `r(sd)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"Treatment")] = `r(mean)' 
			sum `var' if tag_school == 1 & sample_`var' == 1 & treatment == 0 
				mat T[rownumb(T, "`var'"), colnumb(T,"sdC")] = `r(sd)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"Control")] = `r(mean)' 
		} 

		foreach var in $test { 
			global `var'label: var label `var' 
			
			reg `var' treatment, clu(cd_escola) 
				g sample_`var' = (e(sample)==1) 
				local pr = 2*ttail(e(df_r),abs(_b[treatment]/_se[treatment])) 
				mat T[rownumb(T, "`var'"), colnumb(T,"pv")] = `pr' 

			sum `var' if sample_`var' == 1, d
			mat T[rownumb(T, "`var'"), colnumb(T,"n")] = `r(N)' 
			
			sum `var' if sample_`var' == 1 & treatment == 1 
				mat T[rownumb(T, "`var'"), colnumb(T,"sdT")] = `r(sd)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"Treatment")] = `r(mean)'
			sum `var' if sample_`var' == 1 & treatment == 0 
				mat T[rownumb(T, "`var'"), colnumb(T,"sdC")] = `r(sd)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"Control")] = `r(mean)'

			egen max_`var' = max(`var'), by(cd_escola)
			count if max_`var' ~= . & tag_school_test == 1 
			mat T[rownumb(T, "`var'"), colnumb(T,"ns")] = `r(N)' 
		} 

		* Formating Matrix
		matrix list T

		clear 
		svmat T 
		rename T1 ns
		rename T2 n 
		rename T3 Control
		rename T4 sdC
		rename T5 Treatment
		rename T6 sdT
		rename T7 pv

		gen var_name = "" 
		gen var = ""
		order var_name 

		local i = 1 
		foreach var in $xvars { 
			replace var_name = "$`var'label" in `i' 
			replace var = "`var'" in `i' 
			local i = `i' + 1 
		} 

		label var var_name "Variable" 
		label var ns "N (School)" 
		label var n "N (Students)" 
		label var Control "Control" 
		label var sdC "SD" 
		label var Treatment "Treatment" 
		label var sdT "SD" 
		label var pv "p-value" 

		foreach var of varlist n ns { 
			replace `var' = round(`var', 1) 
			format `var' %9.0f 
		} 

		foreach var of varlist Treatment Control sdT sdC { 
			replace `var' = round(`var', 0.01) 
			format `var' %9.2f 
		} 

		foreach var of varlist pv { 
			replace `var' = round(`var', 0.001) 
			format `var' %9.3f 
		} 

		gen stars = "" 
		replace stars = "*" if pv <= 0.10 
		replace stars = "**" if pv <= 0.05 
		replace stars = "***" if pv <= 0.01 

		foreach x in female dumm_rp_08_bl dumm_rp_09_bl dumm_rp_24_bl dumm_rp_14_bl dumm_rp_23_bl dumm_rp_49_bl dumm_rp_50_bl dumm_rp_65A_bl dumm_rp_64A_bl dumm_negotiates_bl {
			foreach y in sdC sdT {
				replace `y' = . if var == "`x'" 
			}
		}
		drop var

		* Output
		export excel using "$results\table1.xlsx" , firstrow(variables) sheet("table 1") sheetreplace


*table A1 - Analysis of Attrition in Long-Term IE Sample
	
		
							
	use "$dta\intervention_data.dta", clear	
		keep if round==1
		
				
		gen sample1=0
		replace sample1=1 if sample==1

		   
			   
	foreach sample in  baseline_sample fup1_sample fup2_sample short_sample {
		reg sample1 treatment  if `sample'==1, clu(cd_escola)
			
			unique cd_escola if e(sample)==1
				local n_schools "`r(unique)'"	
			sum sample1 if e(sample)==1 & treatment==0
				local mean_dep "`r(mean)'"
		
			outreg2 using  tableA1, label excel ctitle(`sample') addstat(number of schools, `n_schools', Dependent variable mean in control group, `mean_dep') addtext(cluster, cd_escola) append
	   }

		*estimate again without clusters for the joint test using suest (clusters added back at that command)
		reg sample1 treatment  if baseline_sample==1 
			estimates store reg1

		reg sample1 treatment  if fup1_sample==1 
			estimates store reg2

		reg sample1 treatment  if fup2_sample==1 
			estimates store reg3

		 
		suest reg1 reg2 reg3, cluster(cd_escola)
		test ([reg1_mean]) ([reg2_mean]) ([reg3_mean])
	
	

* table A2 - Attrition and Students Characteristics 

	use "$dta\intervention_data.dta", clear
		keep if round==1


		gen sample1=0
		   replace sample1=1 if sample==1
	   
		sort cd_escola id_geral
		egen tag_school = tag(cd_escola)
		egen tag_school_test = tag(cd_escola) if bl_test == 1
		egen tag_school_aluno = tag(cd_escola) if bl_aluno == 1

		* Outcomes
		local test female dumm_rp_08_bl dumm_rp_09_bl dumm_rp_24_bl dumm_rp_14_bl dumm_rp_23_bl   
		local aluno dumm_rp_50_bl  dumm_rp_49_bl vl_proficiencia_bl dumm_rp_65A_bl poupar_final2_bl dumm_rp_64A_bl dumm_negotiates_bl autonomia_final2_bl 
		local school matriculas docentes abandonona1sriemdio aprovaona1sriemdio 

		local att_vars `test' `aluno'


		local xvars `test' `aluno' `school' 

		*gen interacted variables and label them using original variables labes
		foreach var in `att_vars'{
			
			gen tX`var'= treatment*`var'
			label var tX`var' "treatment X `:var lab `var''"	
			}
			
			
		



		
	*(1) 	run regression adding characteristics
			reg sample1 treatment  ///
				female dumm_rp_08_bl dumm_rp_09_bl dumm_rp_24_bl dumm_rp_14_bl dumm_rp_23_bl  ///
				dumm_rp_50_bl  dumm_rp_49_bl vl_proficiencia_bl dumm_rp_65A_bl poupar_final2_bl dumm_rp_64A_bl dumm_negotiates_bl autonomia_final2_bl  ///
				, clu(cd_escola)

			capture drop esample
			gen esample=1 if e(sample) // this esample we keep fixed from here on
				
			unique cd_escola if esample==1
				local n_schools "`r(unique)'"	
		
			sum sample1 if esample==1 & treatment==0
				local mean_dep "`r(mean)'"
		
			outreg2 using  tableA2, label excel ctitle(`y') addstat(number of schools, `n_schools', Dependent variable mean in control group, `mean_dep') addtext(cluster, cd_escola) append

			
	*(2) 	run regression adding characteristics
			reg sample1 treatment  ///
				female dumm_rp_08_bl dumm_rp_09_bl dumm_rp_24_bl dumm_rp_14_bl dumm_rp_23_bl  ///
				dumm_rp_50_bl  dumm_rp_49_bl vl_proficiencia_bl dumm_rp_65A_bl poupar_final2_bl dumm_rp_64A_bl dumm_negotiates_bl autonomia_final2_bl  ///
				tX* , clu(cd_escola)
		
			test tXfemale tXdumm_rp_08_bl tXdumm_rp_09_bl tXdumm_rp_24_bl tXdumm_rp_14_bl tXdumm_rp_23_bl tXdumm_rp_50_bl tXdumm_rp_49_bl tXvl_proficiencia_bl tXdumm_rp_65A_bl tXpoupar_final2_bl tXdumm_rp_64A_bl tXdumm_negotiates_bl tXautonomia_final2_bl
				local Ftest "`r(p)'"

			unique cd_escola if esample==1
				local n_schools "`r(unique)'"	

			sum sample1 if esample==1 & treatment==0
				local mean_dep "`r(mean)'"

			outreg2 using  tableA2, label excel ctitle(`y') addstat(number of schools, `n_schools', F-test p-value: joint significance of interaction terms, `Ftest', Dependent variable mean in control group, `mean_dep') addtext(cluster, cd_escola) append

					


* table A3 - Baseline Characteristics of  Short-Term vs. Long-Term IE Sample 

	use "$dta\intervention_data.dta", clear
					keep if round==1 & sample==1
		count
		local n1=`r(N)'
		append using "$dta\intervention_data.dta"
		keep if round==1
		gen sample1=1 if _n<=`n1'
			replace sample1=0 if sample1==.			
			

		sort cd_escola id_geral
		egen tag_school = tag(cd_escola) if sample1==1
			egen tag_school_whole = tag(cd_escola) if sample1==0
			replace tag_school = tag_school_whole if sample1==0
			drop tag_school_whole

	
		* Outcomes
		local test female dumm_rp_08_bl dumm_rp_09_bl dumm_rp_24_bl dumm_rp_14_bl dumm_rp_23_bl dumm_rp_50_bl ///
		dumm_rp_49_bl vl_proficiencia_bl dumm_rp_65A_bl poupar_final2_bl dumm_rp_64A_bl dumm_negotiates_bl autonomia_final2_bl 
		local school matriculas docentes abandonona1sriemdio aprovaona1sriemdio 
		local xvars `school'  `test' 

		* Matrix for output
		local z: word count `xvars' 

		matrix T = J(`z', 9, . ) 
		matrix rownames T = `xvars' 
		matrix colnames T = ns_whole n_whole whole_sample sdWS ns_sample1 n_sample1 sample1 sdS1 pv 

		* Estimation
		foreach var in `school' { 
			global `var'label: var label `var' 

			reg `var' sample1 if tag_school == 1, clu(cd_escola)
				g sample_`var' = (e(sample)==1) 
				local pr = 2*ttail(e(df_r),abs(_b[sample1]/_se[sample1])) 
				mat T[rownumb(T, "`var'"), colnumb(T,"pv")] = `pr' 
			
			
			sum `var' if tag_school == 1 & sample_`var' == 1 & sample1 == 1 
				mat T[rownumb(T, "`var'"), colnumb(T,"ns_sample1")] = `r(N)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"sdS1")] = `r(sd)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"sample1")] = `r(mean)' 
			sum `var' if tag_school == 1 & sample_`var' == 1 & sample1 == 0 
				mat T[rownumb(T, "`var'"), colnumb(T,"ns_whole")] = `r(N)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"sdWS")] = `r(sd)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"whole_sample")] = `r(mean)' 
		} 
		foreach var in `test' { 
			global `var'label: var label `var' 
			
			reg `var' sample1, clu(cd_escola) 
				g sample_`var' = (e(sample)==1) 
				local pr = 2*ttail(e(df_r),abs(_b[sample1]/_se[sample1])) 
				mat T[rownumb(T, "`var'"), colnumb(T,"pv")] = `pr' 

			
			sum `var' if sample_`var' == 1 & sample1 == 1 
				mat T[rownumb(T, "`var'"), colnumb(T,"n_sample1")] = `r(N)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"sdS1")] = `r(sd)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"sample1")] = `r(mean)'
			sum `var' if sample_`var' == 1 & sample1 == 0 
				mat T[rownumb(T, "`var'"), colnumb(T,"n_whole")] = `r(N)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"sdWS")] = `r(sd)' 
				mat T[rownumb(T, "`var'"), colnumb(T,"whole_sample")] = `r(mean)'

			unique 	cd_escola if sample_`var' == 1 & sample1 == 1
				mat T[rownumb(T, "`var'"), colnumb(T,"ns_sample1")] = `r(unique)'
			unique 	cd_escola if sample_`var' == 1 & sample1 == 0
				mat T[rownumb(T, "`var'"), colnumb(T,"ns_whole")] = `r(unique)'
				
		} 

		

		* Formating Matrix
		matrix list T

		clear 
		svmat T 
		rename T1 ns_whole  
		rename T2 n_whole 
		rename T3 whole_sample  
		rename T4 sdWS 
		rename T5 ns_sample1 
		rename T6 n_sample1 
		rename T7 sample1 
		rename T8 sdS1
		rename T9 pv

		gen var_name = "" 
		gen var = ""
		order var_name 

		local i = 1 
		foreach var in `xvars' { 
			replace var_name = "$`var'label" in `i' 
			replace var = "`var'" in `i' 
			local i = `i' + 1 
		} 


		label var var_name "Variable" 
		label var ns_whole "N (School in whole sample)" 
		label var ns_sample1 "N (School in identified sample)" 
		label var n_whole "N (Students in whole sample)" 
		label var n_sample1 "N (Students in identified sample)" 
		label var whole_sample "Whole sample" 
		label var sdWS "SD" 
		label var sample1 "Identified" 
		label var sdS1 "SD" 
		label var pv "p-value" 

		foreach var of varlist n_whole n_sample1 ns_whole ns_sample1 { 
			replace `var' = round(`var', 1) 
			format `var' %9.0f 
		} 

		foreach var of varlist whole_sample sample1 sdS1 sdWS { 
			replace `var' = round(`var', 0.01) 
			format `var' %9.2f 
		} 

		foreach var of varlist pv { 
			replace `var' = round(`var', 0.001) 
			format `var' %9.3f 
		} 

		gen stars = "" 
		replace stars = "*" if pv <= 0.10 
		replace stars = "**" if pv <= 0.05 
		replace stars = "***" if pv <= 0.01 

		foreach x in female dumm_rp_08_bl dumm_rp_09_bl dumm_rp_24_bl dumm_rp_14_bl dumm_rp_23_bl dumm_rp_49_bl dumm_rp_50_bl dumm_rp_65A_bl dumm_rp_64A_bl dumm_negotiates_bl {
			foreach y in sdWS sdS1 {
				replace `y' = . if var == "`x'" 
			}
		}
		drop var

		* Output
		

		export excel using "$results\tableA3.xlsx" , firstrow(variables) sheet("table A3") sheetreplace
		

		
*table A4 - Short-Term Effects by Sample 
		
	use "$dta\intervention_data.dta", clear

		foreach samp in all 1{
		preserve
		capture keep if sample==`samp'
		* Outcomes
		local outcomes vl_proficiencia_fup dumm_rp_53B_fup  dumm_rp_55_fup dumm_rp_56_fup 

		* Estimation
		est drop _all
		local i = 1
		foreach var of varlist `outcomes' { 

			bys pair_all: egen flag_`var'0=mean(treatment) if `var'~=. & round==0
			gen pair_`var'0=pair_all
			replace pair_`var'0=0 if flag_`var'0==0 | flag_`var'0==1
			
			bys pair_all: egen flag_`var'1=mean(treatment) if `var'~=. & round==1
			gen pair_`var'1=pair_all
			replace pair_`var'1=0 if flag_`var'1==0 | flag_`var'1==1			
			
			
			local bl "" 
			local bl = subinstr("`var'","_fup","_bl",.) 
			gen miss_`bl' = 0 
			replace miss_`bl' = 1 if `bl' == . 
			replace `bl' = 0 if `bl' == . 
			
			areg `var' treatment `bl' miss_`bl' female_coded miss_f_coded if round==0, a(pair_`var'0) r clu(cd_escola)
			summ `var' if treatment == 0 & e(sample) == 1 
				estadd scalar controlmean = r(mean)
				estadd scalar controlsd = r(sd)
			est sto table1_`i'

			
			local ++ i 
			
			areg `var' treatment `bl' miss_`bl' female_coded miss_f_coded if round==1, a(pair_`var'1) r clu(cd_escola)
			summ `var' if treatment == 0 & e(sample) == 1 
				estadd scalar controlmean = r(mean)
				estadd scalar controlsd = r(sd)
			est sto table1_`i'

			
			local ++ i 
		
		} 


		* Output:
		if "`samp'"=="all" {
			local title "PanelA"
		} 
		else{
			local title "PanelB"
		}
		#delimit ;
		esttab table1_* using "tableA4_`title'.csv", replace modelwidth(16) varwidth(30) depvar legend label 
			keep(treatment) cells(b(star fmt(%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01)
			stats(r2 N N_clust controlmean controlsd , fmt(%9.3f %9.0g %9.0g %9.3f %9.3f %9.3f) labels("R-squared" "N" "Number of Clusters" "Dependent Variable Mean in Control Group" "Dependent Variable SD in Control Group" )) ;
		#delimit cr

		***********************************************************************
		restore
		}


***************************************************************************
***																		***
*** Dataset for tables 2 through 5, and A5 through A12, A14 and A15  	***
***																		***
***************************************************************************
	cd "$results" 


	use "$dta\main_panel.dta", replace



*UFxMonth FE

 egen uf_month=group(month cd_uf)
 gen year=floor(month/100)

* Time heterogeneity
********************

		gen period_12_18=0
			replace period_12_18=1 if month>=201200 & month <201900
			
		gen period_16_18=0
			replace period_16_18=1 if month>=201606 & month <201900
			
		gen period_19_21=0
			replace period_19_21=1 if month>=201900  
	
	*het time x treatment
		gen treatment_12_18=0 
			replace treatment_12_18=1 if treatment==1 & treatment_12_18!=. & month>=201200 &  month <201900  
				
		gen treatment_16_18=0 
			replace treatment_16_18=1 if treatment==1 & treatment_16_18!=. & month>=201606 & month <201900
			
		gen treatment_19_21=0 
			replace treatment_19_21=1 if treatment==1 & treatment_19_21!=. & month>=201900 


* Loss variables definition
*********************
			
		gen any_delay_notloss=0
			replace any_delay_notloss=1 if  maxdelay>0 & maxdelay<=360 & maxdelay!=. 

		gen any_loss=0
			replace any_loss=1 if  maxdelay>360 & maxdelay!=. 
			
		gen any_delay_notloss_2=0
			replace any_delay_notloss_2=1 if  maxdelay2>0 & maxdelay2<=360 & maxdelay2!=. 

		gen any_loss_2=0
			replace any_loss_2=1 if  maxdelay2>360 & maxdelay2!=. 

		gen treatment_loss201606=treatment*loss201606

	
* Occupation variables
**********************

		gen entrepreneur=0
			replace entrepreneur=1 if mei==1|firm_owner==1
	
		*auxílio emergencial ahead (brought to 2019)
		bysort cpf_hash: egen ae_max=max(ae_dummy) 
			replace ae_max=. if year!=2019

		foreach var in d_employed marc_pbf_all mei { 	
			gen `var'_2019=`var' if year==2019
			bysort cpf_hash: egen `var'_2019_max=max(`var'_2019) if year==2019
			drop `var'_2019 
			}	
	
		gen informal_proxy=0 if month==201912	
			replace informal_proxy=1 if month==201912 & d_employed_2019_max==0 & marc_pbf_all_2019_max==0 & mei_2019_max==0	

		gen ln_avg_wage_pos=log(avg_wage)	
	
		gen nfemp=0
			replace nfemp=1 if d_employed==0
			
		gen treatment_nfemp=treatment*nfemp
			gen treatment_no_nfemp=treatment*(1-nfemp)			
	
* Extensive winsorized inflation adjusted balances	
***********************************************************	



		gen balance_ext_201912=balance*factor_ipca_201912 if month>=201201
					replace balance_ext_201912=0 if balance_ext_201912==. & month>=201201


		foreach cat in ccpurch creditcarddebt overdrafts nonpayrollloans auto payrollloans {
			gen `cat'_ext_201912 =val`cat'*factor_ipca_201912 if month>=201201
					replace  `cat'_ext_201912=0 if `cat'_ext_201912==. & month>=201201
		}


		foreach var in balance ccpurch creditcarddebt overdrafts nonpayrollloans auto payrollloans {
			
			ren `var'_ext_201912 `var'_ext_

			winsor2 `var'_ext_ if month>=201606 & month<=202002, cuts(0 99) suffix(tp99)
			winsor2 `var'_ext_ if month>=201606 & month<=202002, cuts(0 98) suffix(tp98)

		} 
 

* Prepare occupation categories and PNAD income - end of sample position
***************************************************************


	bysort cpf_hash: egen max_ae_dummy=max(ae_dummy) 

	gen occupation =""
		replace occupation ="formal business owner" if d_emp==1 & (month==201912|month==202002)
		replace occupation ="formally self-employed" if entrepreneur==1 & occupation=="" & (month==201912|month==202002)
		replace occupation ="formally employed" if d_employed==1 & occupation=="" & (month==201912|month==202002)
		replace occupation ="PBF" if  marc_pbf_all ==1  & occupation=="" & (month==201912|month==202002)
		replace occupation="informal proxy" if max_ae_dummy==1 & occupation=="" & (month==201912|month==202002)
		

	merge m:1 female cd_uf occupation using "$dta\PNAD_wages_draft.dta", keepus(VD4020 VD4020_no_PBF )
		drop _merge

		gen lab_income=VD4020
			replace lab_income=VD4020_no_PBF if occupation=="informal proxy"
				
		gen lab_income_ext=lab_income
			replace lab_income_ext=0 if lab_income_ext==. & (month==201912 | month==202002)

		drop lab_income
			

	
			
			
*  Compute results
********************			
			
			
			
			
* table 2 - Long-Term Effects on Holding Accounts at Financial Institution 

		local tab table2
		local var relationship

		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
			
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
			
	*Pre-intervention
		
		*Panel A - Controlling for state-month fixed effects, school pair dummies and student gender
		reghdfe `var' treatment  						female 	if month>=200801 & month<=200912, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

	*post intervention
		*Panel A - Controlling for state-month fixed effects, school pair dummies and student gender
		reghdfe `var' treatment  						female 	if month>=201201 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding time varying treatment effects
		reghdfe `var' treatment_12_18 treatment_19_21  	female 	if month>=201201 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							
							test treatment_12_18=treatment_19_21 
								mat def B=r(p)  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)

							tabstat `var' if treatment==0 & esample==1 & period_12_18==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							tabstat `var' if treatment==0 & esample==1 & period_19_21==1 , stats(mean) save
								mat def B=B\r(StatTotal)	
								
							mat def v=v,B
							mat drop B
							drop esample

		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
		mat drop v

		
		
*Table 3 - Long-Term effects on credit usage

		local tab table3
		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
			
			
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
				
			
	foreach var in d_balance d_creditcardpurchases d_creditcarddebt d_overdrafts {

		*Panel A - Controlling for state-month fixed effects, school pair dummies and student gender
		reghdfe `var' treatment  						female 	if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding time varying treatment effects
		reghdfe `var' treatment_16_18 treatment_19_21  	female 	if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							
							test treatment_16_18=treatment_19_21 
								mat def B=r(p)  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)

							tabstat `var' if treatment==0 & esample==1 & period_12_18==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							tabstat `var' if treatment==0 & esample==1 & period_19_21==1 , stats(mean) save
								mat def B=B\r(StatTotal)	
								
							mat def v=v,B
							mat drop B
							drop esample
	}
		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
				mat drop v


				
*Table 4 - Long-Term Effects on Default

		local tab table4
		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
		
		
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
				
			
	foreach var in any_delay_notloss any_loss any_delay_notloss_2 any_loss_2 {

		*Panel A - Controlling for state-month fixed effects, school pair dummies and student gender
		reghdfe `var' treatment  						female 	if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding time varying treatment effects
		reghdfe `var' treatment_16_18 treatment_19_21  	female 	if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							
							test treatment_16_18=treatment_19_21 
								mat def B=r(p)  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)

							tabstat `var' if treatment==0 & esample==1 & period_12_18==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							tabstat `var' if treatment==0 & esample==1 & period_19_21==1 , stats(mean) save
								mat def B=B\r(StatTotal)	
								
							mat def v=v,B
							mat drop B
							drop esample
	}
		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
		mat drop v

		

*Table 5 - Long-Term effects on Formal Firm Ownership, Formal Employment, and Informallity Proxy

		local tab table5
		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
			
			
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
				
			
	foreach var in entrepreneur mei firm_owner d_employed informal_proxy {

		*Panel A - Controlling for state-month fixed effects, school pair dummies and student gender
		*OBS: for the infomal_proxy this regression estimates result presented in Panel B.
		reghdfe `var' treatment  						female 	if month>=201201 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample
		
		if (!inlist("`var'","informal_proxy")){
		*Panel B - Adding school pair dummies and student gender and time varying treatment effects
		reghdfe `var' treatment_12_18 treatment_19_21  	female 	if month>=201201 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							
							test treatment_12_18=treatment_19_21 
								mat def B=r(p)  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)

							tabstat `var' if treatment==0 & esample==1 & period_12_18==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							tabstat `var' if treatment==0 & esample==1 & period_19_21==1 , stats(mean) save
								mat def B=B\r(StatTotal)	
								
							mat def v=v,B
							mat drop B
							drop esample
		}
	}
		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
		mat drop v		
						
* Table A5: Timeline
* Built manually							
				

				
* Table A6 - Long-Term Effects on Holding Accounts at Financial Institutions - Specifications With Fewer Control Variables

		local tab tableA6
		local var relationship

		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
			
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
			
	*Pre-intervention
		*Panel A - Controlling only for state-month fixed effects
		reghdfe `var' treatment  								if month>=200801 & month<=200912, abs(uf_month) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, No, UF x month FE, Yes, cluster, cd_escola)
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding school pair dummies
		reghdfe `var' treatment  								if month>=200801 & month<=200912, abs(uf_month pair_all) clu(cd_escola) 
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

	
	*post intervention
		*Panel A - Controlling only for state-month fixed effects
		reghdfe `var' treatment  								if month>=201201 & month<=202002, abs(uf_month) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, No, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding school pair dummies
		reghdfe `var' treatment  								if month>=201201 & month<=202002, abs(uf_month pair_all) clu(cd_escola) 
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		

		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
		mat drop v

		
		
* Table A7 - Long-Term Effects on Credit Usage - Specifications With Fewer Control Variables

		local tab tableA7
		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
			
			
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
				
			
	foreach var in d_balance d_creditcardpurchases d_creditcarddebt d_overdrafts d_nonpayrollloans d_auto d_payrollloans {

		*Panel A - Controlling only for state-month fixed effects
		reghdfe `var' treatment  								if month>=201606 & month<=202002, abs(uf_month) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, No, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding school pair dummies
		reghdfe `var' treatment  								if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola) 
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

	}
		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
				mat drop v



* Table A8 - Long-Term Effects on Default - Specifications With Fewer Control Variables

		local tab tableA8
		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
		
		
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
				
			
	foreach var in any_delay_notloss any_loss any_delay_notloss_2 any_loss_2 {

		*Panel A - Controlling only for state-month fixed effects
		reghdfe `var' treatment  								if month>=201606 & month<=202002, abs(uf_month) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, No, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding school pair dummies
		reghdfe `var' treatment  								if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola) 
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample
	}
		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
		mat drop v

		
		
* Table A9 - Long-Term Effects on Formal Firm Ownership and Formal Employment - Specifications With Fewer Control Variables				

		local tab tableA9
		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
			
			
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
				
			
	foreach var in entrepreneur mei firm_owner d_employed {

		*Panel A - Controlling only for state-month fixed effects
		reghdfe `var' treatment  								if month>=201201 & month<=202002, abs(uf_month) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, No, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding school pair dummies
		reghdfe `var' treatment  								if month>=201201 & month<=202002, abs(uf_month pair_all) clu(cd_escola) 
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample
	}
	
		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
		mat drop v	

		

* Table A10 - Long-Term Effects on Credit Usage in Less Common Categories

		local tab tableA10
		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
			
			
		mat def v =(1\2\3\4\5\6\7) 
		capture drop esample 
				
			
	foreach var in d_nonpayrollloans d_auto d_payrollloans {

		*Panel A - Controlling for state-month fixed effects, school pair dummies and student gender
		reghdfe `var' treatment  						female 	if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
							mat def B=B\. 
							mat def B=B\.
								
							mat def v=v,B
							mat drop B
							drop esample

		*Panel B - Adding time varying treatment effects
		reghdfe `var' treatment_16_18 treatment_19_21  	female 	if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							
							test treatment_16_18=treatment_19_21 
								mat def B=r(p)  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)

							tabstat `var' if treatment==0 & esample==1 & period_12_18==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							tabstat `var' if treatment==0 & esample==1 & period_19_21==1 , stats(mean) save
								mat def B=B\r(StatTotal)	
								
							mat def v=v,B
							mat drop B
							drop esample
	}
		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				replace v1="1st period - mean control" if _n==6
				replace v1="2nd period - mean control" if _n==7
					
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
				mat drop v
				
				
				
* table A11 - Long-Term Effect on Credit Balance

		local tab tableA11
		capture mat drop v B
		capture	erase "$results\\`tab'_dta.dta"
		capture	erase "$results\\`tab'.txt"
		capture	erase "$results\\temp_v.dta"
			
			
		mat def v =(1\2\3\4\5) 
		capture drop esample 
				
			
	foreach var in balance ccpurch creditcarddebt overdrafts nonpayrollloans auto payrollloans {
	 foreach winsor in tp99 tp98 {
	
		*With state-month fixed effects, school pair dummies and student gender
		reghdfe `var'_ext_`winsor' treatment  						female 	if month>=201606 & month<=202002, abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle("`var'_ext_`winsor'") addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append	
							mat def B=.  
							
								gen esample=1 if e(sample)
							unique cpf_hash if esample==1
								mat def B=B\r(unique)
							unique month if esample==1
								mat def B=B\r(unique)
							unique cd_escola if esample==1
								mat def B=B\r(unique)
							tabstat `var'_ext_`winsor' if treatment==0 & esample==1 , stats(mean) save
								mat def B=B\r(StatTotal)
							
														
							mat def v=v,B
							mat drop B
							drop esample


	 }
	}
		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="equal effect in both periods (p-value)" if _n==1
				replace v1="n students" if _n==2
				replace v1="n months" if _n==3
				replace v1="n school" if _n==4
				replace v1="mean control" if _n==5
				
				save  "temp_v.dta", replace

				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
				erase "$results\\`tab'_dta.dta"
				erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
		mat drop v
				
		

* table A12 - Long-Term Effects on Predicted Income

	 
		local tab tableA12

 		capture mat drop B
		capture mat drop v
		mat def v=(1)
		 
	foreach var in  lab_income_ext {
		 
		reghdfe `var' treatment if month==202002, abs(uf_month) clu(cd_escola) 
		outreg2 using  `tab', dta ctitle(`var') addtext(School Pair FE, No, UF x month FE, Yes, cluster, cd_escola) append

		tabstat `var' if treatment==0 & e(sample) , stats(mean) save

		mat def B=r(StatTotal)
		mat def v=v,B
		mat drop B

				
		reghdfe `var' treatment if month==202002 , abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle(`var') addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append

		tabstat `var' if treatment==0 & e(sample) , stats(mean) save

		mat def B=r(StatTotal)
		mat def v=v,B
		mat drop B


		reghdfe `var' treatment female if month==202002 , abs(uf_month pair_all) clu(cd_escola)
		outreg2 using  `tab', dta ctitle(`var') addtext(School Pair FE, Yes, UF x month FE, Yes, cluster, cd_escola) append

		tabstat `var' if treatment==0 & e(sample) , stats(mean) save

		mat def B=r(StatTotal)
		mat def v=v,B
		mat drop B

		

		preserve
				clear
				svmat v
				tostring _all, replace force
				*name outputs to export
				replace v1="mean control" if _n==1
				
				save  "temp_v.dta", replace
				use "$results\\`tab'_dta.dta", replace
				append using "temp_v.dta"
						export excel using "$results\\`tab'.xlsx" , sheet("income_no_PBF_informal") sheetreplace
				erase "$results\\`tab'_dta.dta"
				captur erase "$results\\`tab'.txt"
				erase "$results\\temp_v.dta"
		restore
			
			mat drop v		
	}
	
	
	
* Table A14 - Robustness: Long-Term Effects on Credit usage by Credit Losses in June 2016

	local tab tableA14
 
	
		capture mat drop v B
		capture	erase "$results\\`var'_dta.dta"
		capture	erase "$results\\`var'.txt"
		capture	erase "$results\\temp_v.dta"
		mat def v =(1\2\3\4) 
		
	foreach var in d_balance d_creditcardpurchases d_creditcarddebt d_overdrafts d_nonpayrollloans d_auto d_payrollloans {
		
		
		capture drop esample   		
						
		*additional effect of having a loss
			di("(3b2) uf_month, female and pair_all 201606 on")
			reghdfe `var' treatment loss201606 treatment_loss201606 female  ///
						if month>=201606	& month<=202002 , abs(uf_month pair_all) clu(cd_escola) 
				outreg2 using  `tab', dta ctitle(`var') addtext(School Pair FE, Yes, UF x month FE, Yes, Municipality x month FE, No, cluster, cd_escola) append

						gen esample=1 if e(sample)
						unique cpf_hash if esample==1
						mat def B=r(unique)
						unique month if esample==1
						mat def B=B\r(unique)
						unique cd_escola if esample==1
						mat def B=B\r(unique)
						tabstat `var' if treatment==0 & esample==1 , stats(mean) save
						mat def B=B\r(StatTotal)
						
						mat def v=v,B
						mat drop B
						unique cpf_hash if esample==1
						drop esample			
		


	}
		preserve
			clear
			svmat v
			tostring _all, replace force
			*name outputs to export
			replace v1="n students" if _n==1
			replace v1="n months" if _n==2
			replace v1="n school" if _n==3
			replace v1="mean control" if _n==4
			

			save  "temp_v.dta", replace
			use "$results\\`tab'_dta.dta", replace
			append using "temp_v.dta"
					export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
			erase "$results\\`tab'_dta.dta"
			erase "$results\\`tab'.txt"
			erase "$results\\temp_v.dta"
		restore
		
		mat drop v



* Table A15 - Robustness: Long-Term Effects on Credit Usage and Wages by Formally Employed Status 

		local tab tableA15
	 
		capture mat drop v B
		capture	erase "$results\\`var'_dta.dta"
		capture	erase "$results\\`var'.txt"
		capture	erase "$results\\temp_v.dta"
			
		mat def v =(1\2\3\4) 

	foreach var in d_balance d_creditcardpurchases d_creditcarddebt d_overdrafts d_nonpayrollloans d_auto d_payrollloans {


	
		capture drop esample   		
						
		*additional effect of having a loss
			di("(3b2) uf_month, female and pair_all 201606 on")
			reghdfe `var' treatment nfemp treatment_nfemp female  ///
						if month>=201606	& month<=202002 , abs(uf_month pair_all) clu(cd_escola) 
				outreg2 using  `tab', dta ctitle(`var') addtext(School Pair FE, Yes, UF x month FE, Yes, Municipality x month FE, No, cluster, cd_escola) append

						gen esample=1 if e(sample)
						unique cpf_hash if esample==1
						mat def B=r(unique)
						unique month if esample==1
						mat def B=B\r(unique)
						unique cd_escola if esample==1
						mat def B=B\r(unique)
						tabstat `var' if treatment==0 & esample==1 , stats(mean) save
						mat def B=B\r(StatTotal)
						
						mat def v=v,B
						mat drop B
					*	unique cpf_hash if esample==1
						drop esample			
	


	}
	
*include wages for the last column: 
		reghdfe ln_avg_wage_pos treatment female  ///
					if month>=201606	& month<=202002 , abs(uf_month pair_all) clu(cd_escola) 
			outreg2 using  `tab', dta ctitle(ln_avg_wage_pos) addtext(School Pair FE, Yes, UF x month FE, Yes, Municipality x month FE, No, cluster, cd_escola) append

					gen esample=1 if e(sample)
					unique cpf_hash if esample==1
					mat def B=r(unique)
					unique month if esample==1
					mat def B=B\r(unique)
					unique cd_escola if esample==1
					mat def B=B\r(unique)
					tabstat ln_avg_wage_pos if treatment==0 & esample==1 , stats(mean) save
					mat def B=B\r(StatTotal)
					
					mat def v=v,B
					mat drop B
				*	unique cpf_hash if esample==1
					drop esample	

		preserve
			clear
			svmat v
			tostring _all, replace force
			*name outputs to export
			replace v1="n students" if _n==1
			replace v1="n months" if _n==2
			replace v1="n school" if _n==3
			replace v1="mean control" if _n==4
			

			save  "temp_v.dta", replace
			use "$results\\`tab'_dta.dta", replace
			append using "temp_v.dta"
					export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
			erase "$results\\`tab'_dta.dta"
			erase "$results\\`tab'.txt"
			erase "$results\\temp_v.dta"
		restore
		
		mat drop v

*************************
*	
*     Figures
*
**************************		


replace relationship=. 			if	month<200801 | month>202002
replace d_balance=. 			if month<201606	| month>202002
replace any_delay_notloss_2=. 	if month<201606	| month>202002
replace any_loss_2=. 			if month<201706	| month>202002
replace mei=.						if month<201504	| month>202002
replace entrepreneur=.			if month<201504	| month>202002
replace d_employed=. 			if month<201301	| month>202002

drop if month<200801 | month>202002

collapse (mean) mean_relationship=relationship mean_balance=d_balance mean_any_del_noloss2=any_delay_notloss_2 mean_any_loss2=any_loss_2 ///
				 mean_mei=mei mean_employed=d_employed mean_entrepreneur=entrepreneur mean_firm_owner=firm_owner ///
 		  (sd) sd_relationship=relationship sd_balance=d_balance sd_any_del_noloss2=any_delay_notloss_2 sd_any_loss2=any_loss_2 ///
				sd_mei=mei sd_employed=d_employed sd_entrepreneur=entrepreneur sd_firm_owner=firm_owner ///
		  (count) n_relationship=relationship n_balance=d_balance n_any_del_noloss2=any_delay_notloss_2 n_any_loss2=any_loss_2 ///
				 n_mei=mei n_employed=d_employed n_entrepreneur=entrepreneur n_firm_owner=firm_owner ///
		  (sum) sum_relationship=relationship sum_balance=d_balance sum_any_del_noloss2=any_delay_notloss_2 sum_any_loss2=any_loss_2 ///
				sum_mei=mei sum_employed=d_employed sum_entrepreneur=entrepreneur sum_firm_owner=firm_owner ///
				,by(treatment month)

foreach var in relationship balance any_del_noloss2 any_loss2 mei employed entrepreneur firm_owner {
	gen `var'_ll=mean_`var'-1.96*sd_`var'/sqrt(n_`var')
	gen `var'_ul=mean_`var'+1.96*sd_`var'/sqrt(n_`var')
}				


foreach var in relationship balance any_del_noloss2 any_loss2 mei employed entrepreneur firm_owner {
di "`var'"	
replace `var'_ll=. if sum_`var'<100 & sum_`var'!=.
replace `var'_ul=. if sum_`var'<100 & sum_`var'!=.
replace mean_`var'=. if sum_`var'<100 & sum_`var'!=.
}

tostring(month), gen(month_string)

gen month_x=date(month_string, "YM")
				
format month_x %tdmonCCYY //show just month and year

keep mean* *_ll *_ul month_x treatment
reshape wide mean* *_ll *_ul, i(month_x) j(treatment)

cd "$results"

set scheme s2color //previous default style for stata graphs




local var relationship 
graph twoway line mean_`var'0 mean_`var'1 `var'_ll0 `var'_ul0 `var'_ll1 `var'_ul1 month_x if mean_`var'0!=., ///
			lcolor( navy maroon navy navy maroon maroon)  ///
			lpattern(solid solid dash dash dot dot) ///
			lwidth( .3  .3  .1 .1  .5 .5) ///
			subtitle("Panel A. Students Holding Accounts at Financial Institutions") ///
			ytitle("Proportion of students", size(small)) xtitle("") ///
			legend(order(1 "Control" 2 "Treatment") pos(6) col(2)) ///
			graphregion(color(white)) 
			
			
			graph export "$results/fig1-PanelA.png"		, as(png) replace

local var balance 

graph twoway line mean_`var'0 mean_`var'1 `var'_ll0 `var'_ul0 `var'_ll1 `var'_ul1 month_x if mean_`var'0!=., ///
			lcolor( navy maroon navy navy maroon maroon)  ///
			lpattern(solid solid dash dash dot dot) ///
			lwidth( .3  .3  .1 .1  .5 .5) ///
			subtitle("Panel B. Students With Any Type of Credit") ///
			ytitle("Proportion of students", size(small)) xtitle("") ///
			legend(order(1 "Control" 2 "Treatment") pos(6) col(2)) ///
			graphregion(color(white)) 
			
			
			graph export "$results/fig1-PanelB.png"		, as(png) replace

local var any_del_noloss2 

graph twoway line mean_`var'0 mean_`var'1 `var'_ll0 `var'_ul0 `var'_ll1 `var'_ul1 month_x if mean_`var'0!=., ///
			lcolor( navy maroon navy navy maroon maroon)  ///
			lpattern(solid solid dash dash dot dot) ///
			lwidth( .3  .3  .1 .1  .5 .5) ///
			subtitle("Panel C. Students With Credit Repayments Delays") ///
			ytitle("Proportion of students", size(small)) xtitle("") ///
			legend(order(1 "Control" 2 "Treatment") pos(6) col(2)) ///
			graphregion(color(white)) 
			
			
			graph export "$results/fig1-PanelC.png"		, as(png) replace

local var any_loss2 

graph twoway line mean_`var'0 mean_`var'1 `var'_ll0 `var'_ul0 `var'_ll1 `var'_ul1 month_x if mean_`var'0!=., ///
			lcolor( navy maroon navy navy maroon maroon)  ///
			lpattern(solid solid dash dash dot dot) ///
			lwidth( .3  .3  .1 .1  .5 .5) ///
			subtitle("Panel D. Students With Credit Losses") ///
			ytitle("Proportion of students", size(small)) xtitle("") ///
			legend(order(1 "Control" 2 "Treatment") pos(6) col(2)) ///
/*			title("Figure `var'- mean+/- 1.96sd/sqrt(N)")  */ graphregion(color(white)) 
			
			
			graph export "$results/fig1-PanelD.png"		, as(png) replace
			
local var entrepreneur

graph twoway line mean_`var'0 mean_`var'1 `var'_ll0 `var'_ul0 `var'_ll1 `var'_ul1 month_x if mean_`var'0!=., ///
			lcolor( navy maroon navy navy maroon maroon)  ///
			lpattern(solid solid dash dash dot dot) ///
			lwidth( .3  .3  .1 .1  .5 .5) ///
			subtitle("Panel A. Students Owning Any Formal Firm") ///
			ytitle("Proportion of students", size(small)) xtitle("") ///
			legend(order(1 "Control" 2 "Treatment") pos(6) col(2)) ///
			graphregion(color(white)) 
			
			
			graph export "$results/fig2-PanelA.png"		, as(png) replace

local var mei 

graph twoway line mean_`var'0 mean_`var'1 `var'_ll0 `var'_ul0 `var'_ll1 `var'_ul1 month_x if mean_`var'0!=., ///
			lcolor( navy maroon navy navy maroon maroon)  ///
			lpattern(solid solid dash dash dot dot) ///
			lwidth( .3  .3  .1 .1  .5 .5) ///
			subtitle("Panel B. Students Owning a Formal Microenterprise") ///
			ytitle("Proportion of students", size(small)) xtitle("") ///
			legend(order(1 "Control" 2 "Treatment") pos(6) col(2)) ///
			graphregion(color(white)) 
			
			
			graph export "$results/fig2-PanelB.png"		, as(png) replace

local var firm_owner 

graph twoway line mean_`var'0 mean_`var'1 `var'_ll0 `var'_ul0 `var'_ll1 `var'_ul1 month_x if mean_`var'0!=., ///
			lcolor( navy maroon navy navy maroon maroon)  ///
			lpattern(solid solid dash dash dot dot) ///
			lwidth( .3  .3  .1 .1  .5 .5) ///
			subtitle("Panel C. Students Owning a Larger Formal Firm") ///
			ytitle("Proportion of students" , size(small)) xtitle("") ///
			legend(order(1 "Control" 2 "Treatment") pos(6) col(2)) ///
			graphregion(color(white)) 
			
			
			graph export "$results/fig2-PanelC.png"		, as(png) replace

local var employed

graph twoway line mean_`var'0 mean_`var'1 `var'_ll0 `var'_ul0 `var'_ll1 `var'_ul1 month_x if mean_`var'0!=., ///
			lcolor( navy maroon navy navy maroon maroon)  ///
			lpattern(solid solid dash dash dot dot) ///
			lwidth( .3  .3  .1 .1  .5 .5) ///
			subtitle("Panel D. Students Who Are Formal Employees") ///
			ytitle("Proportion of students", size(small)) xtitle("") ///
			legend(order(1 "Control" 2 "Treatment") pos(6) col(2)) ///
			graphregion(color(white)) 
			
			
			graph export "$results/fig2-PanelD.png"		, as(png) replace		

	
	
***************************************
***									***
*** Coarser Dataset for table A13 	***
***									***
***************************************


use "$dta\coarser_panel.dta", replace


						
		destring cd_escola, replace //this is necessary to us in reghdfe

		egen uf_month=group(month cd_uf)
		
		gen any_delay_notloss=0
			replace any_delay_notloss=1 if  maxdelay>0 & maxdelay<=360 & maxdelay!=. 			

*Table A13 - Robustness: Long-Term Effect in Less Precisely Matched Sample
			cd "$results"
			 
		local tab tableA13
			 
		capture mat drop v B
		capture	erase "$results\\`var'_dta.dta"
		capture	erase "$results\\`var'.txt"
		capture	erase "$results\\temp_v.dta"
			
		mat def v =(1\2\3\4) 
	foreach var in relationship d_balance any_delay_notloss mei d_employed {

		if(inlist("`var'","d_balance","any_delay_notloss")){
			local begin 201606
			} 
		else{
			local begin 201201
			}
		
		capture drop esample 

		reghdfe `var' treatment   female if month>=`begin' & month<=202002 , abs(uf_month pair_all) clu(cd_escola)	
		outreg2 using  `tab', dta ctitle(`var') addtext(School Pair FE, Yes, UF x month FE, Yes, Municipality x month FE, No, cluster, cd_escola) append

				gen esample=1 if e(sample)
				unique cpf_hash if esample==1
				mat def B=r(unique)
				unique month if esample==1
				mat def B=B\r(unique)
				unique cd_escola if esample==1
				mat def B=B\r(unique)
				tabstat `var' if treatment==0 & esample==1 , stats(mean) save
				mat def B=B\r(StatTotal)
				
				mat def v=v,B
				mat drop B
				unique cpf_hash if esample==1
				drop esample			
	}
			preserve
					clear
					svmat v
					tostring _all, replace force
					*name outputs to export
					replace v1="n students" if _n==1
					replace v1="n months" if _n==2
					replace v1="n school" if _n==3
					replace v1="mean control" if _n==4
					

					save  "temp_v.dta", replace
					use "$results\\`tab'_dta.dta", replace
					append using "temp_v.dta"
							export excel using "$results\\`tab'.xlsx" , sheet("`tab'") sheetreplace
					erase "$results\\`tab'_dta.dta"
					erase "$results\\`tab'.txt"
					erase "$results\\temp_v.dta"
				restore
				
				mat drop v

clear




log close
*******************************************************************


	
